package com.fufu.fileexport;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.List;

/**
 * 导出任务
 */
class ExportTask implements Runnable {
    private final Sheet sheet;
    private final List<DataType> data;
    private final int startRow;
    private final Object lock;

    public ExportTask(Sheet sheet, List<DataType> data, int startRow, Object lock) {
        this.sheet = sheet;
        this.data = data;
        this.startRow = startRow;
        this.lock = lock;
    }

    @Override
    public void run() {
        int rowNum = startRow;
        for (DataType record : data) {
            synchronized (lock) {
                Row row = sheet.createRow(rowNum++);
                row.createCell(0).setCellValue(record.getColumn1());
                row.createCell(1).setCellValue(record.getColumn2());
                row.createCell(2).setCellValue(record.getColumn3());
                row.createCell(3).setCellValue(record.getColumn4());
                row.createCell(4).setCellValue(record.getColumn5());
                row.createCell(5).setCellValue(record.getColumn6());
                row.createCell(6).setCellValue(record.getColumn7());
                row.createCell(7).setCellValue(record.getColumn8());
                row.createCell(8).setCellValue(record.getColumn9());
                row.createCell(9).setCellValue(record.getColumn10());
                row.createCell(10).setCellValue(record.getColumn11());
                row.createCell(11).setCellValue(record.getColumn12());
            }
        }
    }
}
